package searchmethods;

import agent.State;
import java.util.List;
import utils.NodePriorityQueue;

public class UniformCostSearch extends GraphSearch<NodePriorityQueue> {

    public UniformCostSearch(){
        frontier = new NodePriorityQueue();
    }    
    
    // f = g
    public void addSuccessorsToFrontier(List<State> successors, Node parent) {
        
        for(State sucessor: successors){
            double g = parent.getG() + sucessor.getAction().getCost();
            
            if(!frontier.containsState(sucessor)){
                Node n = new Node(sucessor, parent, g , g);
                frontier.add(n);
            }else if(frontier.getNode(sucessor).getG() > g){
                frontier.removeNode(sucessor);
                Node n = new Node(sucessor, parent, g , g);
                frontier.add(n);
            }
        }
    }

    @Override
    public String toString() {
        return "Uniform cost search";
    }
}
